package com.zjq.designpatterns.struct.composite.code;/*
 * 版权信息: 北京千⾥马网信科技有限公司</br>
 * Copyright ©2008-2018. All rights reserved. 京ICP备16007318号
 */

import java.util.ArrayList;
import java.util.List;

/**
 * 目录中有很多课程，课程又是目录组件
 * @author jessie
 * @version 1.0
 * @date 2021/1/23
 */
public class CourseCatalog extends CatalogComponent{
    private List<CatalogComponent> items = new ArrayList<>();
    private String name;
    //弥补组合模式的不足，增加一个level
    private Integer level;

    public CourseCatalog(String name, Integer level) {
        this.name = name;
        this.level = level;
    }

    @Override
    public void add(CatalogComponent catalogComponent) {
        items.add(catalogComponent);
    }

    @Override
    public void remove(CatalogComponent catalogComponent) {
        items.remove(catalogComponent);
    }

    @Override
    public void print() {
        System.out.println(this.name);
        for(CatalogComponent catalogComponent: items){
            if(this.level!=null){
                for(int i=0;i<this.level;i++){
                    System.out.print(" ");
                }
            }
            catalogComponent.print();
        }
    }
}
